let API_HOST = "https://www.zhikelang.com/pet";
function ajax(url = '',type, data = {}, fn) {
  let header = { "Content-Type": "application/json" };
  let app = getApp();
  let token = app.globalData.token;
  if (token){
    header = { "Content-Type": "application/json", 'authorization':token}
  };
  console.info("data -->"+data+' token->'+ token);
  wx.request({
    url: API_HOST + url,
    method: type,
    data: data, ///Object.assign({ "Key": "SurTimeWebserviceS3ur0ti1me8" }, data),
    header: header,
    success: function (res) {
      if (res.data.code ==200){
        fn(res);
      }else{
        wx.showToast({
          title: res.errMsg,
          icon: "none"
        })
        return false;
      }
    },
    fail: function (error) {
      wx.hideLoading();
      wx.showToast({
        title: error.errMsg,
        icon: "none"
      })
    }
  });
}
//去空格
function trim(str) {
  return str.replace(/(^\s*)|(\s*$)/g, "");
}
module.exports = {
  ajax: ajax,
  trim: trim
}
